[8.x](backport #40742) azure-eventhub: expand input sanitizer's invalid JSON coverage#40854
Merged
[8.x](backport #40742) azure-eventhub: expand input sanitizer's invalid JSON coverage#40854
Conversation
- Rework the input's invalid JSON sanitization feature to support configurable sanitizers
- Migrate existing sanitizers to the new format
- Add a new `replace_all` sanitizer
- Add a new `invalid_json_messages_total` input metric to count the number of messages that contain invalid JSON strings.
The `replace_all` sanitizer replaces all the occurrences of substring matching the regex expression `pattern` with a fixed literal string `replacement`.
Here is a sample configuration:
```yaml
sanitizers:
- type: replace_all
spec:
pattern: '\[\s*([^\[\]{},\s]+(?:\s+[^\[\]{},\s]+)*)\s*\]'
replacement: "{}"
```
For example, if the diagnostic settings send the following message:
```json
{
"AppImage": "orcas/postgres_standalone_16_u18:38.1.240825",
"AppType": "PostgreSQL",
"properties": [
218 B blob data
]
}
```
With the previous sample configuration, the input will replace the invalid JSON, updating the message to the following version:
```json
{
"AppImage": "orcas/postgres_standalone_16_u18:38.1.240825",
"AppType": "PostgreSQL",
"properties": {}
}
```
The `replace_all` sanitizer aims to restore JSON syntax validity by replacing invalid, unfixable JSON with literal values that make sense for the context.
The invalid JSON sanitization became a thing when we faced Azure services producing malformed JSON documents.
Here is a list of previous occurrences of this problem:
- #34092
- https://github.com/elastic/azuremarketplacedev/issues/190
In all cases, we first contacted Azure support, but they didn't fix the invalid JSON.
---------
Co-authored-by: Gabriel Pop <94497545+gpop63@users.noreply.github.com>
(cherry picked from commit 168b13a)
|
This pull request doesn't have a |
zmoog
approved these changes
Sep 17, 2024
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed commit message
replace_allsanitizerinvalid_json_messages_totalinput metric to count the number of messages that contain invalid JSON strings.The
replace_allsanitizer replaces all the occurrences of substring matching the regex expressionpatternwith a fixed literal stringreplacement.Here is a sample configuration:
For example, if the diagnostic settings send the following message:
{ "AppImage": "orcas/postgres_standalone_16_u18:38.1.240825", "AppType": "PostgreSQL", "properties": [ 218 B blob data ] }With the previous sample configuration, the input will replace the invalid JSON, updating the message to the following version:
{ "AppImage": "orcas/postgres_standalone_16_u18:38.1.240825", "AppType": "PostgreSQL", "properties": {} }The
replace_allsanitizer aims to restore JSON syntax validity by replacing invalid, unfixable JSON with literal values that make sense for the context.The invalid JSON sanitization became a thing when we faced Azure services producing malformed JSON documents.
Here is a list of previous occurrences of this problem:
In all cases, we first reached out to Azure support, but they didn't fix the invalid JSON.
Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Disruptive User Impact
Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs
This is an automatic backport of pull request #40742 done by [Mergify](https://mergify.com).